{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e2996fea",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langchain-ai/langchain-academy/blob/main/module-2/multiple-schemas.ipynb) [![Open in LangChain Academy](https://cdn.prod.website-files.com/65b8cd72835ceeacd4449a53/66e9eba12c7b7688aa3dbb5e_LCA-badge-green.svg)](https://academy.langchain.com/courses/take/intro-to-langgraph/lessons/58239434-lesson-3-multiple-schemas)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "693d9912-8d56-46a2-a445-3ee5651fe433",
   "metadata": {},
   "source": [
    "# Multiple Schemas\n",
    "\n",
    "## Review\n",
    "\n",
    "We just covered state schema and reducers.\n",
    "\n",
    "Typically, all graph nodes communicate with a single schema. \n",
    "\n",
    "Also, this single schema contains the graph's input and output keys / channels.\n",
    "\n",
    "## Goals\n",
    "\n",
    "But, there are cases where we may want a bit more control over this:\n",
    "\n",
    "* Internal nodes may pass information that is *not required* in the graph's input / output.\n",
    "\n",
    "* We may also want to use different input / output schemas for the graph. The output might, for example, only contain a single relevant output key.\n",
    "\n",
    "We'll discuss a few ways to customize graphs with multiple schemas."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4d727cc2-5a43-4eb5-9d69-82bbbcc35bd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%capture --no-stderr\n",
    "%pip install --quiet -U langgraph"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29b3d109-6bf2-4271-9775-556ee4bd900d",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "## Private State\n",
    "\n",
    "First, let's cover the case of passing [private state](https://docs.langchain.com/oss/python/langgraph/use-graph-api#pass-private-state-between-nodes) between nodes.\n",
    "\n",
    "This is useful for anything needed as part of the intermediate working logic of the graph, but not relevant for the overall graph input or output.\n",
    "\n",
    "We'll define an `OverallState` and a `PrivateState`.\n",
    "\n",
    "`node_2` uses `PrivateState` as input, but writes out to `OverallState`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "038ca2e4-7d6d-49d5-b213-b38469cde434",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGsAAAFNCAIAAACIXwbEAAAAAXNSR0IArs4c6QAAGlRJREFUeJztnXl8FEW+wGvueybJTO47hBBIwiEQAQMECS5EDIQj4QgKq+y6sr7PKrvrPje7qCBiRJenIqgEV5EFUdAYRC4haMAgEY+EBGIuIZmEzH1f3T3vj+FFnplJ90zPZGqG/v4F3dUzv/mmuru6qrp+NKfTCShIQA92ACEPZZAslEGyUAbJQhkkC2WQLEySxxvUDp3KYTagZj2KOJwYFgJtIwYTMJl0vpjBFzEj41h8ISkJNN/ag6o+W8ePpq4mE5tPA04aX8Tgixk8ARNDQ8Agk0Uz6hGzHjUbEJsFY7HpGXmCzAlCsZTlw6d5bdCoRS7UKp0ARMhY6XmCmCSuD98KFX1dls4mk+amXRjJnLFQxuZ6d2XzzuClk+rmC7oZD8jGTBZ5HyrsNNXrLhxVTrtfOmFmBPGjvDBYs6s3c5IwZ5rE1whDg29Pq1X99vsq4giWJ1pjq//RNeneyLDXBwCYXBSVmi2o2dVL9AAnAfZUdirlViIlw4afvjcc3H6dSEn8s7hmV++keyNTxvD98PcNKVov6ns7LUUrY4cvhmOw8ZSaJ2TkTA//k9ctjafVPAHOzx/uOmjUIk3ndXesPgDAlKKos4cUw5cZzuCFWuWMB2T+jirEmL5QeqFWOUwBjwZVfTYnAGHZ7vOKyXMjlXKb1YR4KuDRYMePpgiZL085vtHc3Gyz2YJ1+PAIxMzOZrOnvR4NdjWZ0vMEAYrpV9TW1q5du9ZisQTlcFwy8oSdTUZPe90b1KsdHD59xJ55fa4+roZE4Gqfi/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ZTI4Dcb96+uPr98TGpBP5diK0Xju//6N/Dt3udDoBcLpt8fxh3RuJCWM8faBVZ5leRKgvmWgv//5t16PSZTyx+6FVu91qNKmHbkcQB5Pp/qlIIo5hEMxfQQBPAWAY5nQ6b58GNohYFO0pNv2ACTMbF//BTUr0oRA1eKPNfPYjdcqkeCKFQ52Ohp4lG+IjY/yX4QUAkJzFT0hj6weM5GILATQ3dGPzhQT1eTfSVLQqxtCns+hHIitEsDAozACxzrjfi1Fj7x4qV/8tRdmhtFvCM1+OUWmxqPWljxG6/A3i9WP5qqeSr3/XZ1AGpIUYRLRyg06uLvuT1y8A+Thv5uOdcozJkabAvjAbEVAE0/bqBHx0/oP4rb+h+D536/IZ7YVaZVxWpCwtVD06nU5Fh0Z9Qz+zNDpnuo9juWTnD355RNnVamYwmQIZXxTND4nhFIcNMQyYjSozg+HMHM+/e74XOYWG4oc5rKgD6241X7tsMmgQZY+FzWMKI9mIHbo12+h0mllvt1nQmBR+ZDQz6y5BSjafRnoAw8/vNKGI06RHLAYUcUD3qhSTTROImXwxg+7X+bUwvhUWWsA7lz9UoAyShTJIFsogWSiDZKEMkuV/AflzNFw1v2vDAAAAAElFTkSuQmCC",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from typing_extensions import TypedDict\n",
    "from IPython.display import Image, display\n",
    "from langgraph.graph import StateGraph, START, END\n",
    "\n",
    "class OverallState(TypedDict):\n",
    "    foo: int\n",
    "\n",
    "class PrivateState(TypedDict):\n",
    "    baz: int\n",
    "\n",
    "def node_1(state: OverallState) -> PrivateState:\n",
    "    print(\"---Node 1---\")\n",
    "    return {\"baz\": state['foo'] + 1}\n",
    "\n",
    "def node_2(state: PrivateState) -> OverallState:\n",
    "    print(\"---Node 2---\")\n",
    "    return {\"foo\": state['baz'] + 1}\n",
    "\n",
    "# Build graph\n",
    "builder = StateGraph(OverallState)\n",
    "builder.add_node(\"node_1\", node_1)\n",
    "builder.add_node(\"node_2\", node_2)\n",
    "\n",
    "# Logic\n",
    "builder.add_edge(START, \"node_1\")\n",
    "builder.add_edge(\"node_1\", \"node_2\")\n",
    "builder.add_edge(\"node_2\", END)\n",
    "\n",
    "# Add\n",
    "graph = builder.compile()\n",
    "\n",
    "# View\n",
    "display(Image(graph.get_graph().draw_mermaid_png()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3dc9cd64-4bd3-4c0a-8f8f-d58c551428e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---Node 1---\n",
      "---Node 2---\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'foo': 3}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.invoke({\"foo\" : 1})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50a29f37-f653-4a56-ad0a-345d7f632ea0",
   "metadata": {},
   "source": [
    "`baz` is only included in `PrivateState`.\n",
    "\n",
    "`node_2` uses `PrivateState` as input, but writes out to `OverallState`.\n",
    "\n",
    "So, we can see that `baz` is excluded from the graph output because it is not in `OverallState`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75a8362f-009b-4ec2-abe5-8fb318e39966",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "## Input / Output Schema\n",
    "\n",
    "By default, `StateGraph` takes in a single schema and all nodes are expected to communicate with that schema. \n",
    "\n",
    "However, it is also possible to [define explicit input and output schemas for a graph](https://docs.langchain.com/oss/python/langgraph/use-graph-api#define-input-and-output-schemas).\n",
    "\n",
    "In these cases, we often define an \"internal\" schema that contains *all* keys relevant to graph operations.\n",
    "\n",
    "But we use specific `input` and `output` schemas to constrain the input and output.\n",
    "\n",
    "First, let's just run the graph with a single schema."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5323068a-907a-438c-8db5-46e5d452ad72",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJMAAAFNCAIAAACLxMqpAAAAAXNSR0IArs4c6QAAIABJREFUeJztnXdcE+f/wJ/kApmEEAJhD1mynLhw4EAFBFxonUXrrLvWtra1tVZrnQVbtVqtq2q17oKtqygKiqPWgSBLRGQnkL0v+f2R/lK/Gob2Lsdd7/2HL7m753k+yTv33HN3z6CYTCZAgkOoWAdA8oaQ5vAKaQ6vkObwCmkOr5Dm8AoNw7LVCkNjnV4lM6jkMGwwGfQ4uD+hUADNnsJ2oLG4EJdvx3W2wywS29/PyRv1JfcU5flKjQpmsiEWl8ZygDhONIMWH+a0aqNSblDJYCoE1ArYP5wd0Jkj8KDbOhJbmtPrjNczxDKxnu9m7x/B9ujAtFnRKNHwXFv+SCmp15lMIDrJ2cHJdqeg7cw9yJFc/1UcneTcqT/PNiXakuK78usZ4vA+3B7D+LYp0UbmLh2u47nYRQ210afCioKb0qI7itHzPW1Qli3alhk/VHsGMgmvDQAQ1suxxzCn3Z8+sUFZqJ9zx9IqO8fwgrs5oFpKu6KpQXc8/fmsrzqgWgq65rKO1gt96OF9HNEron3yvER1+0ITqtUmiuYK8qRKGWyzK3Z7o+CmVCGBew5H6+OjeJ27fKyh+xAn9PJv54T1ciy8KZM16lHKHy1zN86Ke8XxqRAFpfxxQXSS8/UMMUqZo2JOpzHWV2r+C43Jlgnq6kCFgKhKi0bmqJh78lDBcrDdE9Gamprq6mqskreMk6t96X0FGjmjZE7ZIZKNRs6v8vz58+Tk5IKCAkySt4p/BLs8X4lGzsibMxlN8kZ9hwgbmTMYDG/WPDaneuPkbUTgQWdxIYlIh3jOyNdp8iaDRm2kUJFvm2g0mnXr1l29ehUA0LVr12XLlplMppSUFADA8uXLAQCJiYlffPFFXV3d9u3bc3NzFQqFr6/v9OnT4+LizDmMHz8+ICAgICDgyJEjGo1m7969EydO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Kbv1R/6XaojfDmZ01gM52FFqvPfQGnVwuenW7ydRsH1cW05HBQKwu0uk0CmVzb9QoAFj5floIQC3XikpFUz/xsboXQWxhTirSH9tSFRhN5DkuLFTeq40Z7eTTkYV2QbZ4J+4osIuMdmiqlNigLGyR1SmE3jQbaLNdD6Je8c6QSSerV9imOEzQyHXSKumwKTbqk2i7/pbJc9z1cqWsXmmzEm2JXmuoK2mY+inqlzcLNu0pO3aBh6JOKqkm2hR4cpGq4k71lI9seiHHYFzBhYN1cjmV5+kIofMCyMaIn0mAToP23durYDOWp+Cm7OpJEd/LwSXACb+9+URPpbXFjX2SnLsPxmA0M5bj526dbyq5r4RhCseZ5eDKsqOj/ljg32PQw4oGtVykNOoNfqGsAaOdKVRsfnnYj1mtKFSW3FM21RvqKlR0JsTg2GEbj1XsGJBCrNWqDQIvpgOPFtyN7RfGotlhOVYbe3MWjEaTSgarZLBeZ8Q6lpeB7ADLgcbm0jAfZGyhHZkjeS0IOzcD4SHN4RXSHF4hzeEV0hxeIc3hlf8DCpgo0BlGv9sAAAAASUVORK5CYII=",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "class OverallState(TypedDict):\n",
    "    question: str\n",
    "    answer: str\n",
    "    notes: str\n",
    "\n",
    "def thinking_node(state: OverallState):\n",
    "    return {\"answer\": \"bye\", \"notes\": \"... his name is Lance\"}\n",
    "\n",
    "def answer_node(state: OverallState):\n",
    "    return {\"answer\": \"bye Lance\"}\n",
    "\n",
    "graph = StateGraph(OverallState)\n",
    "graph.add_node(\"answer_node\", answer_node)\n",
    "graph.add_node(\"thinking_node\", thinking_node)\n",
    "graph.add_edge(START, \"thinking_node\")\n",
    "graph.add_edge(\"thinking_node\", \"answer_node\")\n",
    "graph.add_edge(\"answer_node\", END)\n",
    "\n",
    "graph = graph.compile()\n",
    "\n",
    "# View\n",
    "display(Image(graph.get_graph().draw_mermaid_png()))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "853fc90c-bf82-4d51-b3a5-ceb0b0ae5233",
   "metadata": {},
   "source": [
    "Notice that the output of invoke contains all keys in `OverallState`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "507d35e6-f65c-4e89-b26e-a0ef7b90be83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'question': 'hi', 'answer': 'bye Lance', 'notes': '... his name is Lance'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.invoke({\"question\":\"hi\"})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5a899c3-e1b0-48eb-9a36-8c787e378ef0",
   "metadata": {},
   "source": [
    "Now, let's use a specific `input` and `output` schema with our graph.\n",
    "\n",
    "Here, `input` / `output` schemas perform *filtering* on what keys are permitted on the input and output of the graph. \n",
    "\n",
    "In addition, we can use a type hint `state: InputState` to specify the input schema of each of our nodes.\n",
    "\n",
    "This is important when the graph is using multiple schemas.\n",
    "\n",
    "We use type hints below to, for example, show that the output of `answer_node` will be filtered to `OutputState`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "682b3d10-c78a-41c2-a5ff-842e1688c95f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJMAAAFNCAIAAACLxMqpAAAAAXNSR0IArs4c6QAAIABJREFUeJztnXdcE+f/wJ/kApmEEAJhD1mynLhw4EAFBFxonUXrrLvWtra1tVZrnQVbtVqtq2q17oKtqygKiqPWgSBLRGQnkL0v+f2R/lK/Gob2Lsdd7/2HL7m753k+yTv33HN3z6CYTCZAgkOoWAdA8oaQ5vAKaQ6vkObwCmkOr5Dm8AoNw7LVCkNjnV4lM6jkMGwwGfQ4uD+hUADNnsJ2oLG4EJdvx3W2wywS29/PyRv1JfcU5flKjQpmsiEWl8ZygDhONIMWH+a0aqNSblDJYCoE1ArYP5wd0Jkj8KDbO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qDQIvpgOPFtyN7RfGotlhOVYbe3MWjEaTSgarZLBeZ8Q6lpeB7ADLgcbm0jAfZGyhHZkjeS0IOzcD4SHN4RXSHF4hzeEV0hxeIc3hlf8DCpgo0BlGv9sAAAAASUVORK5CYII=",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "{'question': 'hi', 'answer': 'bye Lance', 'notes': '... his is name is Lance'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class InputState(TypedDict):\n",
    "    question: str\n",
    "\n",
    "class OutputState(TypedDict):\n",
    "    answer: str\n",
    "\n",
    "class OverallState(TypedDict):\n",
    "    question: str\n",
    "    answer: str\n",
    "    notes: str\n",
    "\n",
    "def thinking_node(state: InputState):\n",
    "    return {\"answer\": \"bye\", \"notes\": \"... his is name is Lance\"}\n",
    "\n",
    "def answer_node(state: OverallState) -> OutputState:\n",
    "    return {\"answer\": \"bye Lance\"}\n",
    "\n",
    "graph = StateGraph(OverallState, input_schema=InputState, output_schema=OutputState)\n",
    "graph.add_node(\"answer_node\", answer_node)\n",
    "graph.add_node(\"thinking_node\", thinking_node)\n",
    "graph.add_edge(START, \"thinking_node\")\n",
    "graph.add_edge(\"thinking_node\", \"answer_node\")\n",
    "graph.add_edge(\"answer_node\", END)\n",
    "\n",
    "graph = graph.compile()\n",
    "\n",
    "# View\n",
    "display(Image(graph.get_graph().draw_mermaid_png()))\n",
    "\n",
    "graph.invoke({\"question\":\"hi\"})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1e5ff21",
   "metadata": {},
   "source": [
    "We can see the `output` schema constrains the output to only the `answer` key."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dad97b85",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
